package com.qihoo.finance.fake.service.impl;

import com.qihoo.finance.fake.dao.FakeDao;
import com.qihoo.finance.fake.entity.FakeEntity;
import com.qihoo.finance.fake.service.FakeSourceService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.List;

@Configuration
@ConditionalOnProperty(name = "fake.provider.source.type", havingValue = "public", matchIfMissing = true)
public class FakeSourceServiceImpl implements FakeSourceService {
    @Resource
    private FakeDao fakeDao;

    @Override
    public List<FakeEntity> loadAll() {
        return fakeDao.selectAll();
    }

    @Override
    public FakeEntity queryFakeOne(String... str) {
        return fakeDao.selectOneByFullMethod(str[0], str[1]);
    }

    @Override
    public List<FakeEntity> loadNewFakeList() {
        return fakeDao.selectNewMethod();
    }

    @Override
    public int updateState(FakeEntity entity, Integer state) {
        return fakeDao.updateInterfaceState(entity.getId(), state);
    }

    @Override
    public List<FakeEntity> loadOfflineFakes() {
        return fakeDao.selectOfflineMethod();
    }

    @Override
    public String queryFakeDbIpResult(String interfaceName, String method, String ip) {
        return fakeDao.selectFakeBaseDbIpResult(interfaceName, method, ip);
    }

    @Override
    public String queryFakeVarietyTypeByIp(String ip) {
        return fakeDao.selectFakeVarietyByIp(ip);
    }
}
